package org.diysearch.helpers;

import java.util.List;

import org.diysearch.dao.interfaces.TagDao;
import org.diysearch.interfaces.Taggable;
import org.diysearch.models.MyTag;
import org.diysearch.models.ObjectTag;
import org.diysearch.models.Tag;
import org.diysearch.tools.BaseTool;

public abstract class TagHelper {
	private static final TagDao dao = (TagDao) BaseTool.IOC_ENGINE.getBean("tagDao");
	
	public static List<Tag> getTags(int item, int oid) throws Exception {
		return dao.findByItemAndOid(item, oid);
	}
	
	public static List<Tag> getMyTags (int uid) throws Exception {
		return dao.findTagsByUser(uid);
	}
	
	public static List<Taggable> getItems (int oid, String tag) throws Exception {
		return dao.findItemsByOid(oid, tag);
	}
	
	// public int save(Tag tag, MyTag myTag, ObjectTag objectTag
	public static int save (String tag, int uid, int oid, int item) throws Exception {
		Tag t = new Tag();
		t.setName(tag);
		
		MyTag mt = new MyTag();
		mt.setUid(uid);
		
		ObjectTag ot = new ObjectTag();
		ot.setOid(oid);
		ot.setItem(item);
		
		return dao.save(t, mt, ot);
	}
	
	public static int delete (int uid, String tag) throws Exception {
		return dao.delete(uid, tag);
	}
	
}
